﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace nbcs_chess_squad
{
    class Piece
    {
        #region Attributes
        //Attributes
        private bool _isWhite;
        private Coordinates _coords = new Coordinates();
        private bool _notMoved;
        private Bitmap _image;
        private string _pieceType;

        #endregion

        #region Properties
        //Properties
        public bool IsWhite
        {
            get { return _isWhite; }
            set { _isWhite = value; }
        }

        public Coordinates Coords
        {
            get { return _coords; }
            set { _coords = value; }
        }

        public bool HasNotMoved
        {
            get { return _notMoved; }
            set { _notMoved = value; }
        }

        public Bitmap Image
        {
            get { return _image; }
            set { _image = value; }
        }

        public string Type
        {
            get { return _pieceType; }
            set { _pieceType = value; }
        }

        #endregion Properties

        #region Events
        //Events
        public Piece()
        {
            HasNotMoved = true;
        }

        public void SetTeamAndImage(int i)
        {
            if (i < 16)
            {
                Type = "Pawn";
            }

            else if (i < 20)
            {
                Type = "Castle";
            }

            else if (i < 24)
            {
                Type = "Knight";
            }

            else if (i < 28)
            {
                Type = "Bishop";
            }

            else if (i < 30)
            {
                Type = "Queen";
            }

            else
            {
                Type = "King";
            }

            switch (Type)
            {
                case ("Pawn"):
                    {
                        if (i < 8)
                        {
                            IsWhite = true;
                            Image = nbcs_chess_squad.Properties.Resources.Pawn_w;
                        }

                        else
                        {
                            IsWhite = false;
                            Image = nbcs_chess_squad.Properties.Resources.Pawn_b;
                        }
                        break;
                    }
                case ("Castle"):
                    {
                        if (i < 18)
                        {
                            IsWhite = true;
                            Image = nbcs_chess_squad.Properties.Resources.Castle_w;
                        }

                        else
                        {
                            IsWhite = false;
                            Image = nbcs_chess_squad.Properties.Resources.Castle_b;
                        }
                        break;
                    }

                case ("Knight"):
                    {
                        if (i < 22)
                        {
                            IsWhite = true;
                            Image = nbcs_chess_squad.Properties.Resources.Knight_w;
                        }

                        else
                        {
                            IsWhite = false;
                            Image = nbcs_chess_squad.Properties.Resources.Knight_b;
                        }
                        break;
                    }
                case ("Bishop"):
                    {
                        if (i < 26)
                        {
                            IsWhite = true;
                            Image = nbcs_chess_squad.Properties.Resources.Bishop_w;
                        }

                        else
                        {
                            IsWhite = false;
                            Image = nbcs_chess_squad.Properties.Resources.Bishop_b;
                        }
                        break;
                    }
            }
        }

        #endregion

        #region Movement

        public Coordinates PossibleMovement(int x, int y, int counter)
        {
            switch (Type)
            {
                case ("Pawn"):
                    {
                        if (IsWhite == true)
                        {
                            y++;
                        }

                        else
                        {
                            y--;
                        }
                        break;
                    }

                case ("Castle"):
                    {
                        if (counter == 0)
                        {
                            x++;
                        }

                        if (counter == 1)
                        {
                            x--;
                        }

                        if (counter == 2)
                        {
                            y++;
                        }

                        if (counter == 3)
                        {
                            y--;
                        }
                        break;
                    }

                case ("Knight"):
                    {
                        //Move around clockwise from 12
                        if (counter == 0)
                        {
                            x++;
                            y = y + 2;
                        }

                        if (counter == 1)
                        {
                            x = x + 2;
                            y++;
                        }

                        if (counter == 2)
                        {
                            x = x + 2;
                            y--;
                        }

                        if (counter == 3)
                        {
                            x++;
                            y = y - 2;
                        }

                        if (counter == 4)
                        {
                            x--;
                            y = y - 2;
                        }

                        if (counter == 5)
                        {
                            x = x - 2;
                            y--;
                        }

                        if (counter == 6)
                        {
                            x = x - 2;
                            y++;
                        }

                        if (counter == 7)
                        {
                            x--;
                            y = y + 2;
                        }
                        break;
                    }

                case ("Bishop"):
                    {
                        if (counter == 0)
                        {
                            x++;
                            y++;
                        }

                        if (counter == 1)
                        {
                            x--;
                            y++;
                        }

                        if (counter == 2)
                        {
                            x--;
                            y--;
                        }

                        if (counter == 3)
                        {
                            x++;
                            y--;
                        }
                        break;
                    }
            }

            Coords.X = x;
            Coords.Y = y;
            return Coords;
        }

        public Coordinates SpecialAttack(int x, int y, bool secondSquare)
        {
            if (IsWhite == true)
            {
                y++;

                if (secondSquare == true)
                {
                    x++;
                }

                else
                {
                    x--;
                    secondSquare = true;
                }
            }

            else
            {
                y--;

                if (secondSquare == true)
                {
                    x++;
                }

                else
                {
                    x--;
                }
            }

            Coords.X = x;
            Coords.Y = y;
            return Coords;
        }

        #endregion
    }
}
